﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Trans.depart;

namespace Trans.member
{
    public partial class Manage_member : Form
    {
        public Manage_member()
        {
            InitializeComponent();
        }

        private void Manage_member_Load(object sender, EventArgs e)
        {
            
            this.tb_memberTableAdapter.Fill(this.dataSet.tb_member);

        }

        private void bt_save_Click(object sender, EventArgs e)
        {
            try
            {

                tbmemberBindingSource.EndEdit();
                tb_memberTableAdapter.Update(dataSet.tb_member);
                this.Close(); 
                MessageBox.Show("操作成功", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (System.Exception ex)
            {
                MessageBox.Show("出错啦" + ex.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            
        }

        private void bt_cancel_Click(object sender, EventArgs e)
        {
            tbmemberBindingSource.CancelEdit();
            this.Close();
        }

        private void bt_depart_Click(object sender, EventArgs e)
        {
            Select_depart f = new Select_depart();
            
            if ((f.ShowDialog()!=DialogResult.Cancel)&&
                (f.HasSelected))
            {
                lb_depart.Text = f.Name_s;
                DataRow row=(DataRow)tbmemberBindingSource.Current;
                row["depart_id"] = f.Id;
            }
        }

        private void tx_name_Validating(object sender, CancelEventArgs e)
        {
            if(tx_name.Text.Length>0)
            {
                error.SetError(tx_name, "");
            }
            else
            {
                error.SetError(tx_name, "请输入姓名");
                e.Cancel = true;
            }
        }

        private void gv_member_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            tb_departTableAdapter.FillById(dataSet.tb_depart, (int)gv_member.Rows[e.RowIndex].Cells["c_departid"].Value);
            lb_depart.Text = (string)dataSet.tb_depart.Rows[0]["name"];
        }

        private void gv_member_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            session.Color_Const.set_gv_color(gv_member);
        }
        
    }
}
